package com.windmill.bean;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;

public class Chat implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Date firstDate;
	private Date lastDate;
	private int dayChat;
	private int weekChat;
	private int monthChat;
	private int yearChat;
	private int totalChat;
	private Map<Integer,Integer> yearChatMap = new HashMap<Integer,Integer>();
	public Chat(){
		this.setFirstDate(new Date());
		this.lastDate = new Date();
	}
	public int getDayChat() {
		return dayChat;
	}
	public void setDayChat(int dayChat) {
		this.dayChat = dayChat;
	}
	public int getWeekChat() {
		return weekChat;
	}
	public void setWeekChat(int weekChat) {
		this.weekChat = weekChat;
	}
	public int getMonthChat() {
		return monthChat;
	}
	public void setMonthChat(int monthChat) {
		this.monthChat = monthChat;
	}
	public int getYearChat() {
		return yearChat;
	}
	public void setYearChat(int yearChat) {
		this.yearChat = yearChat;
	}

	public Map<Integer, Integer> getYearChatMap() {
		return yearChatMap;
	}
	public void setYearChatMap(Map<Integer, Integer> yearChatMap) {
		this.yearChatMap = yearChatMap;
	}
	public int getTotalChat() {
		return totalChat;
	}
	public void setTotalChat(int totalChat) {
		this.totalChat = totalChat;
	}
	public String toString(){
		return "本周("+weekChat+");本月("+monthChat+");今年("+yearChat+");总计("+totalChat+")";
	}
	public void chat() {
		resetChat();
		this.dayChat++;
		this.weekChat++;
		this.monthChat++;
		this.yearChat++;
		this.totalChat++;
	}
	/**
	 * 如果最后日期与当前日期不在同一天，同一周，同一月，同一年
	 */
	private Calendar nowCal = new GregorianCalendar(),
			lastCal = new GregorianCalendar();
	private void resetChat() {
		nowCal.setTime(new Date());		
		lastCal.setTime(this.lastDate);
		if(nowCal.get(Calendar.DAY_OF_YEAR)!=lastCal.get(Calendar.DAY_OF_YEAR)){
			dayChat = 0;			
		}
		if(nowCal.get(Calendar.WEEK_OF_YEAR)!=lastCal.get(Calendar.WEEK_OF_YEAR)){
			weekChat = 0;			
		}
		if(nowCal.get(Calendar.MONTH)!=lastCal.get(Calendar.MONTH)){
//			this.monthChatMap.put(lastCal.get(Calendar.MONTH), monthChat);
			monthChat = 0;			
		}
		if(nowCal.get(Calendar.YEAR)!=lastCal.get(Calendar.YEAR)){
			this.yearChatMap.put(lastCal.get(Calendar.YEAR), yearChat);
			yearChat = 0;			
		}
		this.lastDate = new Date();
	}
	public Date getFirstDate() {
		return firstDate;
	}
	public void setFirstDate(Date firstDate) {
		this.firstDate = firstDate;
	}
	public Date getLastDate() {
		return lastDate;
	}
	public void setLastDate(Date lastDate) {
		this.lastDate = lastDate;
	}
}
